package com.qn.wechat.controller;

import com.jeesuite.mybatis.plugin.pagination.Page;
import com.jeesuite.springweb.model.WrapperResponse;
import com.oneplatform.base.exception.AssertUtil;
import com.oneplatform.base.exception.ExceptionCode;
import com.oneplatform.base.model.PageResult;
import com.qn.wechat.ifservice.dto.SBPromoteDto;
import com.qn.wechat.ifservice.dto.WechatAccountDto;
import com.qn.wechat.ifservice.dto.para.SBPromoteQeuryPara;
import com.qn.wechat.ifservice.dto.para.WeChatAccountQueryPara;
import com.qn.wechat.service.SBPromoteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.HttpMethod;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.xml.ws.ResponseWrapper;

//@Api(value = "/sbpromote",tags = "活动管理")
@RequestMapping(value = "/sbpromote")
@Controller
public class SBPromoteController {


    @Resource
    SBPromoteService sbPromoteService;

    @ApiOperation(value = "获取活动列表")
    @RequestMapping(value = "/getlist", method = RequestMethod.POST)
    public @ResponseBody
    PageResult<SBPromoteDto> getList(@ModelAttribute SBPromoteQeuryPara para) {
        Page<SBPromoteDto> page =sbPromoteService.getList(para);
        return new PageResult<SBPromoteDto>(page.getPageNo(), page.getPageSize(), page.getTotal(), page.getData());
    }

    @ApiOperation(value = "获取活动")
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public @ResponseBody
    WrapperResponse<SBPromoteDto> get(@ModelAttribute SBPromoteQeuryPara para) {

        WrapperResponse<SBPromoteDto> response = new WrapperResponse<>();
        para.setPageNo(1);
        para.setPageSize(1);
        AssertUtil.notBlank(para.getId(),  "id不能为空");

        Page<SBPromoteDto> page = sbPromoteService.getList(para);
        if (page != null && page.getData() != null && page.getData().size() > 0) {
            response.setData(page.getData().get(0));
        }

        return response;

    }

    @ApiOperation(value = "保存活动")
    public @ResponseBody
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    WrapperResponse<String> save(@RequestBody SBPromoteDto dto) {
        return sbPromoteService.save(dto);
    }
}
